// pages/withdrawal/index.js
const {
  post
} = getApp();
Page({
  data: {
    money: 0,
    withdrawal: ''
  },
  // 提现记录
  goToPage(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },
  // 初始化加载
  onLoad: function () {
    post("/extract/load-amount").then(res => {
      if (res.result == 1) {
        this.setData({
          money: res.data.money
        });
      };
    })
  },
  // 全部提现
  allWithdrawal(e) {
    const money = e.currentTarget.dataset.money;
    if (parseInt(money) == 0) {
      wx.showToast({
        title: '暂无提现金额',
        icon: 'none',
        duration: 2000
      })
      return;
    };
    this.setData({
      withdrawal: e.currentTarget.dataset.money
    })
  },
  // 改变金额
  changeWithdrawal(e) {
    console.log(e);
    this.setData({
      withdrawal: e.detail.value
    })
  },
  // 提现
  withdrawal() {
    if (/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/.test(this.data.withdrawal)) {
      post("/extract/put-cash", {
        money: this.data.withdrawal
      }).then(res => {
        if (res.result == 1) {
          wx.showToast({
            title: res.message,
            icon: 'none',
            duration: 2000
          })
        };
      })
    } else {
      wx.showToast({
        title: '金额不正确',
        icon: 'none',
        duration: 2000
      })
    }
  },
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    });
  }
})